using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SPDV
{
    public partial class SPWebForm : Form
    {
        public SPWebData WebData
        {
            set
            {
                SPWebData w = (SPWebData)value;
                if (null != w)
                    ConstructTree(tvWebs.Nodes, w);
                if( tvWebs.Nodes.Count > 0)tvWebs.SelectedNode = tvWebs.Nodes[0];
                tvWebs.ExpandAll();
            }
        }
        private void ConstructTree(TreeNodeCollection tnc, SPWebData wd)
        {
            TreeNode tn = new TreeNode(wd.Title);
            tn.Tag = wd;
            tnc.Add(tn);
            foreach (SPWebData w in wd.Webs)
                ConstructTree(tn.Nodes, w);
        }
        public SPWebForm()
        {
            InitializeComponent();
        }

        private void SPWebForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape) Close();
        }

        private void tvWebs_AfterSelect(object sender, TreeViewEventArgs e)
        {
            pgDetails.SelectedObject = e.Node.Tag;
        }
    }
}